﻿using System;
using System.Collections.Generic;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace WP7Guide
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            
            DataContext = App.ViewModel;
            
            SettingsPanel.DataContext = App.Settings;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }


        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void listOne_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/BouquetPage.xaml?bid=" + listOne.SelectedIndex, UriKind.Relative));
            listOne.SelectedItem = null;
            //this.PanoramaTV.SetValue(Panorama.SelectedItemProperty, ChannelPan);
            //this.PanoramaTV.Measure(new Size()); 
        }

        private void Reload_Click(object sender, RoutedEventArgs e)
        {
            App.ViewModel.CancelLoad();
            App.ViewModel.LastUpdate = DateTime.MinValue;
            App.ViewModel.ResetLoadState();
            App.ViewModel.LoadData();
        }

        private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
        {
            EmailComposeTask mailTask= new EmailComposeTask();
            mailTask.To = "wp7guide@live.de";
            mailTask.Show();
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void MaxDaysBox_LostFocus(object sender, RoutedEventArgs e)
        {
            if (App.IsTrial)
            {
                int maxDays;
                int.TryParse(MaxDaysBox.Text, out maxDays);
                if (maxDays > 1)
                {
                    MaxDaysBox.Text = "1";
                    NavigationService.Navigate(new Uri("/BuyPage.xaml", UriKind.Relative));
                }
            }
        }

        //private void ListTwo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    this.PanoramaTV.SetValue(Panorama.SelectedItemProperty, EventsPan);
        //    this.PanoramaTV.Measure(new Size()); 
        //}

        //private void ListThree_SelectionChanged(object sender, SelectionChangedEventArgs e)
        //{
        //    this.PanoramaTV.SetValue(Panorama.SelectedItemProperty, EventPan);
        //    this.PanoramaTV.Measure(new Size()); 
        //}
    }
}